<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<title></title>
<jsp:include page="../links.jsp"></jsp:include>
</head>
<body>
	<script type="text/javascript">
		var goods_datagrid;
		var goods_searchForm;
		var goods_addDlg;
		var goods_addForm;
		var goods_updateDlg;
		var goods_updateForm;
		$(function() {
			goods_datagrid = $('#goods_datagrid').datagrid({
				url : getRootPath() + '/admin/goodsAction/datagrid.do',
				title : '商品列表',
				iconCls : 'icon-save',
				pagination : true,
				rownumbers : true,
				selectOnCheck : true,
				checkOnSelect : false,
				pageSize : 10,
				pageList : [ 10, 20, 30, 40, 50 ],
				fit : true,
				fitColumns : true,
				nowarp : false,
				border : false,
				idField : 'gid',
				sortOrder : 'asc',
				columns : [ [ {
					title : '',
					field : '0',
					width : 100,
					checkbox : true
				}, {
					title : '商品编号',
					field : 'gid',
					width : 60,
				}, {
					title : '商品名称',
					field : 'name',
					width : 150,
				}, {
					title : '发布人编号',
					field : 'uid',
					width : 60,
				}, {
					title : '图片路径',
					field : 'imgurl',
					width : 150
				//	formatter : function(imgurl, row, index) {//使用formatter格式化刷子
				//		return "<img src='" + getRootPath() + "/" + imgurl + "' width='20px' height='20px'/>";
				//	}
				}, {
					title : '详细介绍',
					field : 'detail',
					width : 150,
					formatter : function(detail, row, index) {
						if (detail.length >= 12) {
							return (detail.substr(0, 12) + "...");
						} else {
							return detail;
						}
					}
				}, {
					title : '商品价格',
					field : 'price',
					width : 50,
					formatter : function(price, row, index) {
						return '￥' + price;
					}
				}, {
					title : '商品类别',
					field : 'type',
					width : 50,
				}, {
					title : '创建时间',
					field : 'createtime',
					width : 120,
				}, {
					title : '点击次数',
					field : 'hitcount',
					width : 50,
				}, {
					title : '新旧程度',
					field : 'level',
					width : 50,
				}, {
					title : '商品所在地',
					field : 'location',
					width : 100,
				} ] ],
				toolbar : [ {
					text : '添加',
					iconCls : 'icon-add',
					handler : function() {
						goods_showAddDlg();
					}
				}, '-', {
					text : '修改',
					iconCls : 'icon-edit',
					handler : function() {
						goods_showUpdateDlg();
					}
				}, '-', {
					text : '删除',
					iconCls : 'icon-remove',
					handler : function() {
						goods_remove();
					}
				} ]
			});//datagrid end
			//过滤查询
			goods_searchForm = $('#goods_searchForm').form();
			goods_doSearch = function() {
				//console.info(serializeObject(goods_searchForm));
				goods_datagrid.datagrid('load', serializeObject(goods_searchForm));
			};
			//重置
			goods_cleanSearch = function() {
				goods_datagrid.datagrid('load', {});
				goods_searchForm.find('input').val('');
			};
			//新增
			goods_addDlg = $('#goods_addDlg').dialog();
			goods_addForm = $('#goods_addForm').form();
			goods_showAddDlg = function() {
				$('#goods_addForm input').val('');
				goods_addDlg.dialog('open')
			};
			goods_doAdd = function() {
				goods_addForm.form('submit', {
					url : '${pageContext.request.contextPath}/admin/goodsAction/add.do',
					success : function(data) {
						var r = $.parseJSON(data);
						if (r && r.success) {
							goods_addDlg.dialog('close');
							goods_cleanSearch();
							$.messager.show({
								title : '提示',
								msg : r.msg,
								showType : 'show'
							});
						} else {
							$.messager.alert('提示', r.msg);
						}
					}
				});
			};
			//修改
			goods_updateDlg = $('#goods_updateDlg').dialog();
			goods_updateForm = $('#goods_updateForm').form();
			goods_showUpdateDlg = function() {
				var selectids = goods_datagrid.datagrid('getChecked');
				if (selectids.length == 1) {
					goods_updateDlg.dialog('open');
					$('#goods_up_gid').val(selectids[0].gid);
					$('#goods_up_uid').val(selectids[0].uid);
					$('#goods_up_name').val(selectids[0].name);
					$('#goods_up_price').val(selectids[0].price);
					$('#goods_up_detail').val(selectids[0].detail);
				} else {
					$.messager.alert('提示', "请勾选一项");
				}
			};
			goods_doUpdate = function() {
				goods_updateForm.form('submit', {
					url : '${pageContext.request.contextPath}/admin/goodsAction/update.do?',
					success : function(data) {
						var r = $.parseJSON(data);
						if (r && r.success) {
							goods_updateDlg.dialog('close');
							goods_cleanSearch();
							$.messager.show({
								title : '提示',
								msg : r.msg,
								showType : 'show'
							});
						} else {
							$.messager.alert('提示', r.msg);
						}
					}
				});
			};
			//删除
			goods_remove = function() {
				var selectids = goods_datagrid.datagrid('getChecked');
				var ids = [];
				if (selectids.length > 0) {
					$.messager.confirm('确认', '您是否要删除当前选中的项目？', function(r) {
						if (r) {
							for (var i = 0; i < selectids.length; i++) {
								ids.push(selectids[i].gid);
							}
							$.ajax({
								url : '${pageContext.request.contextPath}/admin/goodsAction/delete.do',
								data : {
									ids : ids.join(',')
								},
								dataType : 'json',
								success : function(r) {
									goods_datagrid.datagrid('load');
									goods_datagrid.datagrid('unselectAll');
									$.messager.show({
										title : '提示',
										msg : r.msg
									});
								}
							});
						}
					});
				} else {
					$.messager.alert('提示', "请最少勾选一项");
				}
			};
		});
	</script>
	<div class="easyui-layout" data-options="fit:true,border:false">
		<div data-options="region:'north',title:'模糊查询条件：(右边可折叠)'" style="height: 100%;">
			<form id="goods_searchForm" method="post">
				<table style="width: 100%; height: 60%;">
					<tr>
						<th class="th-search-label">商品编号:</th>
						<td><input name="goods.gid" maxLength=10 class="easyui-numberbox" type="text" /></td>
						<th class="th-search-label">商品名:</th>
						<td><input name="goods.name" type="text" /></td>
						<th class="th-search-label">商品类别:</th>
						<td><select class="easyui-combobox" name="goods.type" style="width: 173px" panelHeight="110px">
								<option value=" ">全部</option>
								<option value="1">二手电脑</option>
								<option value="2">二手手机</option>
								<option value="3">二手家电</option>
								<option value="4">二手书籍</option>
								<option value="5">二手其他</option>
						</select> &nbsp;<a class="easyui-linkbutton" style="width: 25%" data-options="iconCls:'icon-search'"
							href="javascript:void(0)" onclick="goods_doSearch();">查询</a></td>
					</tr>
					<tr>
						<th class="th-search-label">价格:</th>
						<td><input name="goods.priceStart" maxLength=10 class="easyui-numberbox" type="text" /></td>
						<th class="th-search-label">至:</th>
						<td><input name="goods.priceEnd" maxLength=10 class="easyui-numberbox" type="text" />
						<th class="th-search-label">新旧程度:</th>
						<td><select class="easyui-combobox" name="goods.level" style="width: 173px" panelHeight="200px">
								<option value="">无要求</option>
								<option value="1">98新</option>
								<option value="2">95新</option>
								<option value="3">9成新</option>
								<option value="4">8成新</option>
								<option value="5">7成新</option>
								<option value="6">6成新</option>
								<option value="7">5成新</option>
								<option value="8">其他</option>
						</select>&nbsp;<a class="easyui-linkbutton" style="width: 25%" data-options="iconCls:'icon-redo'"
							href="javascript:void(0)" onclick="goods_cleanSearch();">清空</a></td>
					</tr>
				</table>
			</form>
		</div>
		<div data-options="region:'center',title:''," style="overflow: hidden;">
			<table id="goods_datagrid">
			</table>
		</div>
		<div id="goods_addDlg"
			data-options="closed:true,modal:true,title:'添加失物',buttons:[
				{text : '添加',iconCls : 'icon-add',handler : function() {goods_doAdd();}},
				{text : '取消',iconCls : 'icon-cancel',handler : function() {goods_addDlg.dialog('close');}}]"
			class="easyui-dialog" style="width: 380px; height: 400px;" align="center">
			<form id="goods_addForm" method="post" enctype="multipart/form-data">
				<table>
					<tr>
						<th class="th-search-label">商品名称:</th>
						<td><input name="goods.name" class="easyui-validatebox" data-options="required:true" /></td>
					</tr>
					<tr>
						<th class="th-search-label">用户编号:</th>
						<td><input name="goods.uid" maxLength=10 class="easyui-numberbox" type="text" /></td>
					</tr>
					<tr>
						<th class="th-search-label">图片:</th>
						<td><input name="image" type="file" /></td>
					</tr>
					<tr>
						<th class="th-search-label">价格:</th>
						<td><input name="goods.price" maxLength=10 class="easyui-numberbox" type="text" /></td>
					</tr>
					<tr>
						<th class="th-search-label">商品类型:</th>
						<td><select class="easyui-combobox" name="goods.type" style="width: 173px" panelHeight="110px">
								<option value="1">二手电脑</option>
								<option value="2">二手手机</option>
								<option value="3">二手家电</option>
								<option value="4">二手书籍</option>
								<option value="5">二手其他</option>
						</select></td>
					</tr>
					<tr>
						<th class="th-search-label">新旧程度:</th>
						<td><select class="easyui-combobox" name="goods.level" style="width: 173px" panelHeight="200px">
								<option value="">无要求</option>
								<option value="1">98新</option>
								<option value="2">95新</option>
								<option value="3">9成新</option>
								<option value="4">8成新</option>
								<option value="5">7成新</option>
								<option value="6">6成新</option>
								<option value="7">5成新</option>
								<option value="8">其他</option>
						</select></td>
					</tr>
					<tr>
						<th class="th-search-label">商品所在地:</th>
						<td><select class="easyui-combobox" name="goods.location" style="width: 173px" panelHeight="110px">
								<option value="1">校本部</option>
								<option value="2">旅顺校区</option>
								<option value="3">教学南区</option>
								<option value="4">爱恩学院</option>
								<option value="6">其他</option>
						</select></td>
					</tr>
					<tr>
						<th>详细介绍:</th>
						<td colspan="2"><textarea name="goods.detail" class="easyui-validatebox"
								style="height: 120px; width: 210px;"></textarea></td>
					</tr>
				</table>
			</form>
		</div>
		<div id="goods_updateDlg"
			data-options="closed:true,modal:true,title:'修改失物信息',buttons:[
				{text : '修改',iconCls : 'icon-save',handler : function() {goods_doUpdate();}},
				{text : '取消',iconCls : 'icon-cancel',handler : function() {goods_updateDlg.dialog('close');}}]"
			class="easyui-dialog" style="width: 380px; height: 420px;" align="center">
			<form id="goods_updateForm" method="post" enctype="multipart/form-data">
				<table>
					<tr>
						<th class="th-search-label">商品编号:</th>
						<td><input id="goods_up_gid" name="goods.gid" class="easyui-validatebox"
							data-options="required:true" readonly="readonly" /></td>
					</tr>
					<tr>
						<th class="th-search-label">商品名称:</th>
						<td><input id="goods_up_name" name="goods.name" class="easyui-validatebox"
							data-options="required:true" /></td>
					</tr>
					<tr>
						<th class="th-search-label">用户编号:</th>
						<td><input id="goods_up_uid" name="goods.uid" class="easyui-validatebox"
							data-options="required:true" /></td>
					</tr>
					<tr>
						<th class="th-search-label">图片:</th>
						<td><input name="image" type="file" /></td>
					</tr>
					<tr>
						<th class="th-search-label">价格:</th>
						<td><input id="goods_up_price" name="goods.price" maxLength=10 class="easyui-numberbox" type="text" /></td>
					</tr>
					<tr>
						<th class="th-search-label">商品类型:</th>
						<td><select class="easyui-combobox" name="goods.type" style="width: 173px" panelHeight="110px">
								<option value="1">二手电脑</option>
								<option value="2">二手手机</option>
								<option value="3">二手家电</option>
								<option value="4">二手书籍</option>
								<option value="5">二手其他</option>
						</select></td>
					</tr>
					<tr>
						<th class="th-search-label">新旧程度:</th>
						<td><select class="easyui-combobox" name="goods.level" style="width: 173px" panelHeight="200px">
								<option value="1">98新</option>
								<option value="2">95新</option>
								<option value="3">9成新</option>
								<option value="4">8成新</option>
								<option value="5">7成新</option>
								<option value="6">6成新</option>
								<option value="7">5成新</option>
								<option value="8">其他</option>
						</select></td>
					</tr>
					<tr>
						<th class="th-search-label">商品所在地:</th>
						<td><select class="easyui-combobox" name="goods.location" style="width: 173px" panelHeight="110px">
								<option value="1">校本部</option>
								<option value="2">旅顺校区</option>
								<option value="3">教学南区</option>
								<option value="4">爱恩学院</option>
								<option value="6">其他</option>
						</select></td>
					</tr>
					<tr>
						<th>详细介绍:</th>
						<td colspan="2"><textarea id="goods_up_detail" name="goods.detail" class="easyui-validatebox"
								style="height: 120px; width: 210px;"></textarea></td>
					</tr>
				</table>
			</form>
		</div>
	</div>
</body>
</html>